package leencode;

import leencode.数据结构.二叉树.TreeNode;
import org.junit.jupiter.api.Test;

public class no100_相同的树 {

    @Test
    public void test(){
        /**
         *      1
         *   n     2
         *       4  n
         *     n  3
         */
        TreeNode p = new TreeNode(1,
                null, new TreeNode(2,new TreeNode(4, null ,new TreeNode(3)),null));

        /**
         *      1
         *   n     4
         *       2  n
         *     n  3
         */
        TreeNode q = new TreeNode(1,
                null, new TreeNode(2,new TreeNode(2),null));


        boolean flag = isSameTree(p,q);

        System.out.println(flag);

    }

    public boolean isSameTree(TreeNode p, TreeNode q) {

        if(p == null && q == null ) return true;

        if((p == null && q != null) || (p != null && q == null)) return false;

        boolean lflag;
        boolean rflag;

        if (p.val != q.val) return false;

        lflag = isSameTree(p.left,q.left);

        rflag = isSameTree(p.right,q.right);


        if(lflag && rflag){

            return true;
        } else {
            return false;
        }


    }
}
